/**     
* @Title: Application.java   
* @Package me.crawler   
* @Description: TODO   
* @author xaoyaoyao
* @date 2019年1月12日 下午1:17:36
*/
package me.crawler;

import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import me.crawler.entry.CrawlManager;

/**
 * @ClassName: Application
 * @Description: TODO
 * @author xaoyaoyao
 * @date 2019年1月12日 下午1:17:36
 * 
 */
@EnableAsync // 异步线程
@EnableScheduling // 定时器执行
@SpringBootApplication
@ComponentScan(basePackages = {"me.crawler"})
public class Application {

	public static void main(String[] args) {
		ApplicationContext applicationContext = SpringApplication.run(Application.class, args);
		CrawlManager manager = applicationContext.getBean(CrawlManager.class);
		manager.execute();
	}

	@Bean
	public Executor taskExecutor() {
		ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
		executor.setCorePoolSize(10);
		executor.setMaxPoolSize(50);
		executor.setQueueCapacity(200);
		executor.setKeepAliveSeconds(60);
		executor.setThreadNamePrefix("AsyncCrawler-");
		executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
		executor.setWaitForTasksToCompleteOnShutdown(true);
		executor.setAwaitTerminationSeconds(60);
		return executor;
	}

}
